import React,{createContext, useReducer, useState} from 'react' 
 
export const CountContext = createContext({})
// 定义一个常量
export const UPDATE = "UPDATE"
export const UPDATE_CODE = "UPDATE_CODE"

const reducer = (state, action) => {
  switch (state, action.type) {
    case UPDATE:
      state.count= action.count
      return state
      case UPDATE_CODE:
        state.isAlert= action.isAlert
        return state
    default:
      return state
  }
}

export default function Count (props) {
  
   const [configData,dispatch] = useReducer(reducer,{count: 15 , isAlert: true})
  return (
    <CountContext.Provider value={{configData,dispatch}}>
      {props.children}
    </CountContext.Provider>
  )
}
